package com.wlw.equipment.mq;

import com.wlw.equipment.constants.MqConstants;
import com.wlw.equipment.service.impl.EquipmentService;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 监听队列，实现数据更新
 *
 * @author lutianqi
 * @date 2022/5/28 16:27
 */
@Component
public class EquipmentListener {
    @Autowired
    private EquipmentService equipmentService;

    /**
     * 监听新增、修改队列
     *
     * @param id 数据库新增设备的id
     */
    @RabbitListener(queues = MqConstants.EQUIPMENT_INSERT_QUEUE)    //监听的队列名
    public void listenerInsertOrUpdate(Long id) {   //发送方发送的是ID，此处也接收ID
        equipmentService.insertOrUpdateById(id);
    }

    /**
     * 监听删除队列
     *
     * @param id 数据库新增设备的id
     */
    @RabbitListener(queues = MqConstants.EQUIPMENT_DELETE_QUEUE)
    public void listenerDelete(Long id) {   //发送方发送的是ID，此处也接收ID
        equipmentService.deleteById(id);
    }
}
